package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.utils.RedisHashUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserRedisController {
    @Autowired
    private RedisHashUtil template;

    @PostMapping("/add")
    public String addUser(@RequestBody User user){
        Map<String,Object> map=new HashMap<>();
        map.put("id",user.getId() );
        map.put("name",user.getUserName());
        map.put("passWord",user.getPassWord());
        map.put("realName",user.getRealName());

        template.addMapAll("user",map);
        return user.toString();
    }
}
